package cn.tedu._07weibopjt.base.interceptors;

import cn.tedu._07weibopjt.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        UserVO userVO = (UserVO) session.getAttribute("user");
        if (userVO == null) {
            response.sendRedirect("/login.html");
            log.debug(request.getRequestedSessionId() + "用户未登录，拦截请求");
            return false;
        }
        log.debug("用户已完成登录，放行");
        return true;
    }
}
